<?php

/**
 * This is the model class for table "alumni".
 *
 * The followings are the available columns in table 'alumni':
 * @property integer $id
 * @property string $alumni_fname
 * @property string $alumni_lname
 * @property string $alumni_address
 * @property integer $alumni_contactnumber
 * @property integer $alumni_age
 * @property string $alumni_gender
 * @property string $alumni_status
 * @property string $alumni_birthday
 * @property string $alumni_picture
 * @property string $alumni_email
 * @property integer $donation_id
 * @property integer $occupation_id
 * @property integer $company_id
 *
 * The followings are the available model relations:
 * @property Company $company
 * @property Donation $donation
 * @property Occupation $occupation
 */
class Alumni extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Alumni the static model class
	 */
	
	
	 
	    public function getNames()
        {
                        return $this->lname.', '. $this->fname.' '. $this->mname;
        }

        const s='Single';
        const w='Widowed';
        const m='Merried';
        const se='Separated';
        const a='Annulled';

        const fe='Female';
        const ma='Male';
        
        public function getGenderOptions()
        {
                return array(
                        self::ma=>'Male',
                        self::fe=>'Female',
                );
        }
        
        public function getCivilStatusOption()
        {
                return array(
                        self::s=>'Single',
                        self::w=>'Widowed',
                        self::m=>'Married',
                        self::se=>'Separated',
                        self::a=>'Annulled',
                );
        }
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'alumni';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			
			array('alumni_fname, alumni_address, alumni_lname, company_id, occupation_id, donation_id', 'required'),
			array('alumni_age, alumni_contactnumber',  'numerical', 'integerOnly'=>true),
			array('alumni_fname, alumni_lname, alumni_address,  alumni_email', 'length', 'max'=>45),
			array('alumni_age', 'length', 'max'=>2),
			array('alumni_status, alumni_picture, alumni_gender, alumni_birthday', 'safe'),
			
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.

			// Please remove those attributes that should not be searched.

			array('id, alumni_fname, alumni_lname, alumni_address, alumni_contactnumber, alumni_age, alumni_gender, alumni_status, alumni_birthday, alumni_picture, alumni_email, donation_id, occupation_id, company_id', 'safe', 'on'=>'search'),
			array('alumni_picture', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'on'=>'update'), 
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
			'donation' => array(self::BELONGS_TO, 'Donation', 'donation_id'),
			'occupation' => array(self::BELONGS_TO, 'Occupation', 'occupation_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'alumni_fname' => 'First Name',
			'alumni_lname' => 'Last Name',
			'alumni_address' => 'Address',
			'alumni_contactnumber' => 'Contact Number',
			'alumni_age' => 'Age',
			'alumni_gender' => 'Gender',
			'alumni_status' => 'Marital Status',
			'alumni_birthday' => 'Birthdate',
			'alumni_picture' => 'Picture',
			'alumni_email' => 'Email',
			'donation_id' => 'Donation',
			'occupation_id' => 'Occupation',
			'company_id' => 'Company',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('alumni_fname',$this->alumni_fname,true);
		$criteria->compare('alumni_lname',$this->alumni_lname,true);
		$criteria->compare('alumni_address',$this->alumni_address,true);
		$criteria->compare('alumni_contactnumber',$this->alumni_contactnumber);
		$criteria->compare('alumni_age',$this->alumni_age);
		$criteria->compare('alumni_gender',$this->alumni_gender,true);
		$criteria->compare('alumni_status',$this->alumni_status,true);
		$criteria->compare('alumni_birthday',$this->alumni_birthday,true);
		$criteria->compare('alumni_picture',$this->alumni_picture,true);
		$criteria->compare('alumni_email',$this->alumni_email,true);
		$criteria->compare('donation_id',$this->donation_id);
		$criteria->compare('occupation_id',$this->occupation_id);
		$criteria->compare('company_id',$this->company_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}
